package jpavlich.cardsorter.action;

import fr.inria.zvtm.animation.ActionTimingHandler;
import fr.inria.zvtm.animation.Animation;
import fr.inria.zvtm.animation.Animation.Dimension;
import fr.inria.zvtm.engine.VirtualSpace;
import fr.inria.zvtm.engine.VirtualSpaceManager;
import fr.inria.zvtm.glyphs.Glyph;
import fr.inria.zvtm.glyphs.IcePDFPageImg;

public class MoveCardToTop extends Action<MoveCardToTop> {

	private String cardID;
	private String vsID;

	public MoveCardToTop(String cardID, String vsID) {
		super();
		this.cardID = cardID;
		this.vsID = vsID;
	}

	@Override
	public void execute() {
		Glyph glyph = (Glyph) getResourceManager().findResource(cardID);
		if (glyph != null) {
			VirtualSpace vs = (VirtualSpace) getResourceManager().findResource(vsID);
			vs.onTop(glyph);
		}
	}

	@Override
	public void undo() {
		Glyph glyph = (Glyph) getResourceManager().findResource(cardID);
		if (glyph != null) {
			// Not implemented
		}
	}

	@Override
	public MoveCardToTop clone() {
		return new MoveCardToTop(cardID, vsID);
	}

	@Override
	public String toString() {
		return "MoveCard [id=" + cardID +", recordable=" + recordable
				+ ", startTime=" + startTime + ", duration=" + duration + "]";
	}

	@Override
	public Animation createAnimation() {
		final Glyph glyph = (Glyph) getResourceManager().findResource(cardID);
		return VirtualSpaceManager.INSTANCE
				.getAnimationManager()
				.getAnimationFactory()
				.createAnimation((int) duration, glyph,
						Animation.Dimension.POSITION,
						new ActionTimingHandler() {

							@Override
							public void begin(Object subject,
									Animation.Dimension dim) {
								execute();
							}

							@Override
							public void timingEvent(float arg0, Object arg1,
									Dimension arg2) {

							}

						});
	}

}
